package com.financing.platform.util;


import java.text.SimpleDateFormat;
import java.util.Date;
public class SequenceManagerNew {

	protected SimpleDateFormat sd = new SimpleDateFormat("yyyyMMdd");

	static protected SimpleDateFormat sd2 = new SimpleDateFormat("yyyyMMddHHmmss");
	//计数器
	static int  counter=1;
	//保证金_code前缀
	static String  BZJ = "bzj_";
	//支付流水_code前缀
	static String  ZFLS = "zfls_";

	//数据库指针，识别不同的分布式系统，假设集群最多9个
	long dbcounter=0;
	
	/**
	 * 获取当前秒数的序列号
	 * 每一秒内并发不超过1000
	 * @return
	 */
	public static synchronized String seq(){
		return seq(null);
	}
	/**
	 * 获取当前秒数的序列号
	 * 每一秒内并发不超过1000
	 * @return
	 */
	public static synchronized String seq(String type){
		String s = sd2.format(new Date());
		if(counter>999){
			counter=0;
		}
		String hou=(""+(counter+1000)).substring(1);
		counter++;
		return type==null?s+hou:type+s+hou;
	}
	
	/**
	 * 获取当前秒数的序列号
	 * 每一秒内并发不超过1000
	 * @return
	 */
	public static  String seq_bzj(){
		return seq(BZJ);
	}
	public static void main(String[] args) {
		//System.out.println(seq());
		for(int i =0;i<1200;i++){
			System.out.println(seq());
			long dbcounter=i%9+1;
			System.out.println(dbcounter);
			
		}
		
	}
	

}
